In [43]:
# Project III
# data was imported and filtered from Our World in Data website
# https://ourworldindata.org/suicide#suicide-is-a-leading-cause-of-death-especially-in-young-people
# and from Kaggle
# https://www.kaggle.com/russellyates88/suicide-rates-overview-1985-to-2016
import pandas as pd 
import os
import matplotlib.pyplot as plt 
import numpy as np
import plotly.express as px
In [44]:
#reading csv files
death = pd.read_csv('deaths.csv', index_col=0, encoding = "ISO-8859-1") 
suicide = pd.read_csv('suicide.csv', index_col=0, encoding = "ISO-8859-1") 
In [45]:
# displaying data in deaths dataset
# detaset is between 1900 and 2017, after filtering by years between 2000 
# and 2017 we have 4290 rows and 34 columns
death.shape
Out[45]:
(4290, 35)
In [46]:
# displaying suicide dataset
# dataset is between 1985 and 2016, after filtering by years between 2000 
# and 2016 we have 16168 rows with 
suicide.shape
Out[46]:
(16168, 9)
In [47]:
# 2016
suicide_2016 = suicide[suicide.year == 2016]
suicide_2016
Out[47]:
country year sex age suicides_no population gdp_for_year ($) gdp_per_capita ($) generation
661 Armenia 2016 male 75+ 12 61956 10,546,135,160 3788 Silent
662 Armenia 2016 male 55-74 16 237813 10,546,135,160 3788 Boomers
663 Armenia 2016 male 35-54 16 350633 10,546,135,160 3788 Generation X
664 Armenia 2016 male 15-24 5 202220 10,546,135,160 3788 Millenials
665 Armenia 2016 female 75+ 2 102414 10,546,135,160 3788 Silent
... ... ... ... ... ... ... ... ... ...
14784 Thailand 2016 female 75+ 69 1589015 411,755,164,833 6713 Silent
14785 Thailand 2016 female 55-74 222 6049756 411,755,164,833 6713 Boomers
14786 Thailand 2016 female 35-54 375 10629684 411,755,164,833 6713 Generation X
14787 Thailand 2016 female 25-34 116 4702656 411,755,164,833 6713 Millenials
14788 Thailand 2016 female 15-24 60 4525574 411,755,164,833 6713 Millenials

160 rows × 9 columns

In [48]:
# cleaning unused data: deleting columns gdp_for_year ($), gdp_per_capita ($) and generation

del suicide_2016[' gdp_for_year ($) '], suicide_2016['gdp_per_capita ($)'], suicide_2016['generation']

suicide_2016
Out[48]:
country year sex age suicides_no population
661 Armenia 2016 male 75+ 12 61956
662 Armenia 2016 male 55-74 16 237813
663 Armenia 2016 male 35-54 16 350633
664 Armenia 2016 male 15-24 5 202220
665 Armenia 2016 female 75+ 2 102414
... ... ... ... ... ... ...
14784 Thailand 2016 female 75+ 69 1589015
14785 Thailand 2016 female 55-74 222 6049756
14786 Thailand 2016 female 35-54 375 10629684
14787 Thailand 2016 female 25-34 116 4702656
14788 Thailand 2016 female 15-24 60 4525574

160 rows × 6 columns

In [51]:
# suicide_2016
arm = suicide_2016.loc[suicide['country'] == 'Armenia', 'suicides_no'].sum()
aus = suicide_2016.loc[suicide['country'] == 'Austria', 'suicides_no'].sum()
cro = suicide_2016.loc[suicide['country'] == 'Croatia', 'suicides_no'].sum()
cyp = suicide_2016.loc[suicide['country'] == 'Cyprus', 'suicides_no'].sum()
cze = suicide_2016.loc[suicide['country'] == 'Czech Republic', 'suicides_no'].sum()
gre = suicide_2016.loc[suicide['country'] == 'Grenada', 'suicides_no'].sum()
hun = suicide_2016.loc[suicide['country'] == 'Hungary', 'suicides_no'].sum()
ice = suicide_2016.loc[suicide['country'] == 'Iceland', 'suicides_no'].sum()
lit = suicide_2016.loc[suicide['country'] == 'Lithuania', 'suicides_no'].sum()
mau = suicide_2016.loc[suicide['country'] == 'Mauritius', 'suicides_no'].sum()
mon = suicide_2016.loc[suicide['country'] == 'Mongolia', 'suicides_no'].sum()
net = suicide_2016.loc[suicide['country'] == 'Netherlands', 'suicides_no'].sum()
qat = suicide_2016.loc[suicide['country'] == 'Qatar', 'suicides_no'].sum()
rom = suicide_2016.loc[suicide['country'] == 'Romania', 'suicides_no'].sum()
swe = suicide_2016.loc[suicide['country'] == 'Sweden', 'suicides_no'].sum()
thai = suicide_2016.loc[suicide['country'] == 'Thailand', 'suicides_no'].sum()

#country = suicide_2016['country'].unique()
total_num = [ 'Armenia', arm], [ 'Austria', aus], ['Croatia', cro], ['Cyprus', cyp], ['Czech Republic', cze], ['Grenada', gre], ['Hungary', hun], ['Iceland', ice], ['Lithuania', lit], ['Mauritius', mau], ['Mongolia', mon], ['Netherlands', net], ['Qatar', qat], ['Romania', rom], ['Sweden', swe], ['Thailand', thai]

total_2016 = pd.DataFrame(total_num, columns = ['Country', 'Total'])

tot_2016 = total_2016.sort_values(by='Total', ascending=False)
tt_2016 = tot_2016.head()
tt_2016
Out[51]:
Country Total
15 Thailand 4117
13 Romania 1953
11 Netherlands 1886
6 Hungary 1761
4 Czech Republic 1318
In [52]:
import plotly.graph_objects as go

labels = tt_2016.Country
values = tt_2016.Total
fig = go.Figure(data = [go.Pie(labels = labels, values = values, pull =[0,0,0,0,0.2], title = 'The Total Number of Suicides in 2016')])
fig.show()
In [53]:
fig_size = plt.rcParams["figure.figsize"]

fig_size[0] = 19
fig_size[1] = 7
plt.rcParams["figure.figsize"] = fig_size
plt.title("Total number of suicides by country in 2016")
plt.scatter(tot_country['Country'], tot_country['Total N'], s=150)
plt.show()
In [54]:
suicide_2016['Percent'] = suicide_2016.suicides_no/suicide_2016.population
suicide_2016.sort_values(by='Percent', ascending=False)
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ipykernel_launcher.py:1: SettingWithCopyWarning:


A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy

Out[54]:
country year sex age suicides_no population Percent
8793 Lithuania 2016 male 75+ 78 80426 0.000970
6733 Hungary 2016 male 75+ 214 246437 0.000868
3633 Croatia 2016 male 75+ 104 134519 0.000773
8794 Lithuania 2016 male 55-74 212 277763 0.000763
8795 Lithuania 2016 male 35-54 266 376689 0.000706
... ... ... ... ... ... ... ...
6944 Iceland 2016 female 75+ 0 11268 0.000000
4000 Cyprus 2016 female 75+ 0 31234 0.000000
11683 Qatar 2016 female 15-24 0 88675 0.000000
11684 Qatar 2016 female 55-74 0 26182 0.000000
9508 Mauritius 2016 female 75+ 0 26298 0.000000

160 rows × 7 columns

In [56]:
# calculating percentage for every country
arm = suicide_2016.loc[suicide['country'] == 'Armenia', 'Percent'].sum()
aus = suicide_2016.loc[suicide['country'] == 'Austria', 'Percent'].sum()
cro = suicide_2016.loc[suicide['country'] == 'Croatia', 'Percent'].sum()
cyp = suicide_2016.loc[suicide['country'] == 'Cyprus', 'Percent'].sum()
cze = suicide_2016.loc[suicide['country'] == 'Czech Republic', 'Percent'].sum()
gre = suicide_2016.loc[suicide['country'] == 'Grenada', 'Percent'].sum()
hun = suicide_2016.loc[suicide['country'] == 'Hungary', 'Percent'].sum()
ice = suicide_2016.loc[suicide['country'] == 'Iceland', 'Percent'].sum()
lit = suicide_2016.loc[suicide['country'] == 'Lithuania', 'Percent'].sum()
mau = suicide_2016.loc[suicide['country'] == 'Mauritius', 'Percent'].sum()
mon = suicide_2016.loc[suicide['country'] == 'Mongolia', 'Percent'].sum()
net = suicide_2016.loc[suicide['country'] == 'Netherlands', 'Percent'].sum()
qat = suicide_2016.loc[suicide['country'] == 'Qatar', 'Percent'].sum()
rom = suicide_2016.loc[suicide['country'] == 'Romania', 'Percent'].sum()
swe = suicide_2016.loc[suicide['country'] == 'Sweden', 'Percent'].sum()
thai = suicide_2016.loc[suicide['country'] == 'Thailand', 'Percent'].sum()

p_total_num = [ 'Armenia', arm], [ 'Austria', aus], ['Croatia', cro], ['Cyprus', cyp], ['Czech Republic', cze], ['Grenada', gre], ['Hungary', hun], ['Iceland', ice], ['Lithuania', lit], ['Mauritius', mau], ['Mongolia', mon], ['Netherlands', net], ['Qatar', qat], ['Romania', rom], ['Sweden', swe], ['Thailand', thai]

p_total_2016 = pd.DataFrame(p_total_num, columns = ['Country', 'Percent'])

p_tot_2016 = p_total_2016.sort_values(by='Percent', ascending=False)
p_perc_tt_2016 = p_tot_2016.head()
p_perc_tt_2016
Out[56]:
Country Percent
8 Lithuania 0.003617
6 Hungary 0.002413
2 Croatia 0.002136
10 Mongolia 0.001844
1 Austria 0.001832
In [59]:
import plotly.graph_objects as go

labels = p_perc_tt_2016.Country
values = p_perc_tt_2016.Percent
fig = go.Figure(data = [go.Pie(labels = labels, values = values, pull =[0,0,0,0,0.2], title = 'The Highest Percentage of Suicides by Country in 2016')])
fig.show()
In [61]:
import plotly.graph_objects as go
from plotly.subplots import make_subplots

labels_1 = tt_2016.Country
labels_2 = p_perc_tt_2016.Country

# Create subplots: use 'domain' type for Pie subplot
fig = make_subplots(rows=1, cols=2, specs=[[{'type':'domain'}, {'type':'domain'}]])
fig.add_trace(go.Pie(labels=labels_1, values=tt_2016.Total, name="The Total Number of Suicides in 2016"),
              1, 1)
fig.add_trace(go.Pie(labels=labels_2, values=p_perc_tt_2016.Percent, name="Total Highest Percentage of Suicides in 2016"),
              1, 2)

# Use `hole` to create a donut-like pie chart
fig.update_traces(hole=.4, hoverinfo="label+percent+name")

fig.update_layout(
    title_text="Total Number of Suicides vs Total Highest Percentage of Suicides in 2016",
    # Add annotations in the center of the donut pies.
    annotations=[dict(text='TNS', x=0.18, y=0.5, font_size=20, showarrow=False),
                 dict(text='THPS', x=0.82, y=0.5, font_size=20, showarrow=False)])
fig.show()
In [62]:
# 2015
suicide_2015 = suicide[suicide.year == 2015]
del suicide_2015[' gdp_for_year ($) '], suicide_2015['gdp_per_capita ($)'], suicide_2015['generation'], suicide_2015['year']

suicide_2015.sort_values(by='population', ascending=False)
Out[62]:
country sex age suicides_no population
15835 United States male 35-54 11634 41658010
15838 United States female 35-54 4053 41531809
15839 United States female 55-74 2872 35115610
15834 United States male 55-74 9068 32264697
2510 Brazil female 35-54 910 28461855
... ... ... ... ... ...
294 Antigua and Barbuda female 75+ 0 1724
12632 Saint Vincent and Grenadines male 75+ 0 1459
6182 Grenada male 75+ 0 1303
300 Antigua and Barbuda male 75+ 0 1087
13028 Seychelles male 75+ 0 1076

744 rows × 5 columns

In [63]:
# The highest number of suicides in by sex
tot_2015 = suicide_2015.groupby(['country', 'sex'])['suicides_no'].sum().reset_index()
tot_2015.sort_values(by='suicides_no', ascending=False)
Out[63]:
country sex suicides_no
121 United States male 33990
91 Russian Federation male 20861
55 Japan male 16146
120 United States female 10199
87 Republic of Korea male 9556
... ... ... ...
96 Seychelles female 1
92 Saint Vincent and Grenadines female 1
42 Grenada female 0
1 Antigua and Barbuda male 0
43 Grenada male 0

124 rows × 3 columns

In [64]:
# The total highest number of suicides by country (male+female)
tot_2015 = suicide_2015.groupby(['country'])['suicides_no'].sum().reset_index()
tot_suicide_2015 = tot_2015.sort_values(by = 'suicides_no', ascending=False)
tot_suicide_2015
Out[64]:
country suicides_no
60 United States 44189
45 Russian Federation 25432
27 Japan 23092
43 Republic of Korea 13510
7 Brazil 11163
... ... ...
6 Belize 26
48 Seychelles 7
46 Saint Vincent and Grenadines 3
0 Antigua and Barbuda 1
21 Grenada 0

62 rows × 2 columns

In [65]:
suicide_2015['Percent'] = suicide_2015.suicides_no/suicide_2015.population
top5_2015_bypercent = suicide_2015.sort_values(by='Percent', ascending=False)

top_5_2015_bypercent = top5_2015_bypercent.head()
top_5_2015_bypercent
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ipykernel_launcher.py:1: SettingWithCopyWarning:


A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy

Out[65]:
country sex age suicides_no population Percent
11867 Republic of Korea male 75+ 1329 944284 0.001407
13569 Slovenia male 75+ 62 62345 0.000994
6721 Hungary male 75+ 221 241730 0.000914
8781 Lithuania male 75+ 67 79672 0.000841
12837 Serbia male 75+ 189 228745 0.000826
In [71]:
import plotly.graph_objects as go
from plotly.subplots import make_subplots

labels_1 = ['United States','Russian Federation','Japan','Republic of Korea', 'Brazil']
labels_2 = ['Republic of Korea','Slovenia','Hungary','Lithuania', 'Serbia']

# Create subplots: use 'domain' type for Pie subplot
fig = make_subplots(rows=1, cols=2, specs=[[{'type':'domain'}, {'type':'domain'}]])
fig.add_trace(go.Pie(labels=labels_1, values=top_5_2015_bypercent.suicides_no, name="Total Suicide Numbers in 2015"),1, 1)
fig.add_trace(go.Pie(labels=labels_2, values=top_5_2015_bypercent.Percent, name="Total Suicides Percentage in 2015"),1, 2)

# Use `hole` to create a donut-like pie chart
fig.update_traces(hole=.4, hoverinfo="label+percent+name")

fig.update_layout(
    title_text="Total Suicide Number vs Total Suicide Percentage in 2015",
    # Add annotations in the center of the donut pies.
    annotations=[dict(text='TSN', x=0.18, y=0.5, font_size=20, showarrow=False),
                 dict(text='TSP', x=0.82, y=0.5, font_size=20, showarrow=False)])
fig.show()
In [72]:
import plotly.express as px

tips = px.data.tips()

fig = px.bar(tips, y = tot_2015.country, x = tot_2015.suicides_no, orientation='h', title ='Total number \
                                                                                    of suicides in 2015')

fig.show()
In [73]:
import plotly.graph_objects as go

fig = go.Figure()
fig.add_trace(go.Bar(
    y=tot_2015.country,
    x=tot_2015.suicides_no,
    name='Male',
    orientation='h',
    marker=dict(
        color='rgba(246, 78, 139, 0.6)',
        line=dict(color='rgba(246, 78, 139, 1.0)', width=3)
    )
))
fig.add_trace(go.Bar(
    y=tot_2015.country,
    x=tot_2015.suicides_no,
    name='Female',
    orientation='h',
    marker=dict(
        color='rgba(58, 71, 80, 0.6)',
        line=dict(color='rgba(58, 71, 80, 1.0)', width=3)
    )
))

fig.update_layout(barmode='stack', title_text = 'Total number of suicides by sex in 2015')
fig.show()
In [74]:
import plotly.graph_objects as go
fig = go.Figure(data = [go.Bar(name = 'Male', x = suicide_2016.country, y=suicide_2016.Percent),
                     go.Bar(name = 'Female', x = suicide_2016.country, y=suicide_2016.Percent)])
fig.update_layout(barmode='stack', title_text ='The Percentage (ratio) number of \ 
                                    suicides and population by gender and by country in 2016')
fig.show()
  File "<ipython-input-74-3f9ee0bf25cb>", line 4
    fig.update_layout(barmode='stack', title_text ='The Percentage (ratio) number of \
                                                                                       ^
SyntaxError: EOL while scanning string literal
In [75]:
import plotly.graph_objects as go
fig = go.Figure(data = [go.Bar(name = 'Male', x = suicide_2016.country, y=suicide_2016.suicides_no),
                     go.Bar(name = 'Female', x = suicide_2016.country, y=suicide_2016.suicides_no)])
fig.update_layout(barmode='stack', title_text ='The number of suicides by gender and by country in 2016')
fig.show()
In [76]:
# creating a variable for every (16) countries for future analysis
suicide_2016_Armenia = suicide_2016[suicide_2016.country == "Armenia"]
suicide_2016_Austria = suicide_2016[suicide_2016.country == "Austria"]
suicide_2016_Croatia = suicide_2016[suicide_2016.country == "Croatia"]
suicide_2016_Cyprus = suicide_2016[suicide_2016.country == "Cyprus"]
suicide_2016_Czech = suicide_2016[suicide_2016.country == "Czech Republic"]
suicide_2016_Grenada = suicide_2016[suicide_2016.country == "Grenada"]
suicide_2016_Hungary = suicide_2016[suicide_2016.country == "Hungary"]
suicide_2016_Iceland = suicide_2016[suicide_2016.country == "Iceland"]
suicide_2016_Lithuania = suicide_2016[suicide_2016.country == "Lithuania"]
suicide_2016_Mauritius = suicide_2016[suicide_2016.country == "Mauritius"]
suicide_2016_Mongolia = suicide_2016[suicide_2016.country == "Mongolia"]
suicide_2016_Netherlands = suicide_2016[suicide_2016.country == "Netherlands"]
suicide_2016_Qatar = suicide_2016[suicide_2016.country == "Qatar"]
suicide_2016_Romania = suicide_2016[suicide_2016.country == "Romania"]
suicide_2016_Sweden = suicide_2016[suicide_2016.country == "Sweden"]
suicide_2016_Thailand = suicide_2016[suicide_2016.country == "Thailand"]
In [77]:
suicide_bar = suicide_2016_Armenia.plot.bar(
    x="age", 
    y="suicides_no",
    title="Suicide number by age in Armenia",
    figsize=(15,5), stacked=True,
    colormap = "viridis")
suicide_bar_1 = suicide_2016_Armenia.plot.bar(
    x="sex", 
    y="suicides_no",
    title="Suicide number by sex in Armenia",figsize=(15,5), 
    stacked=True,colormap = "plasma")
In [78]:
suicide_bar = suicide_2016_Austria.plot.bar(
    x="age", y="suicides_no",
    title="Suicide number by age in Austria",
    figsize=(15,5), stacked=True,colormap = "viridis")

suicide_bar_1 = suicide_2016_Austria.plot.bar(
    x="sex", y="suicides_no",
    title="Suicide number by sex in Austria",
    figsize=(15,5), stacked=True,colormap = "plasma")
In [79]:
suicide_bar = suicide_2016_Croatia.plot.bar(
    x="age", y="suicides_no",
    title="Suicide number by age in Croatia",
    figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Croatia.plot.bar(
    x="sex", y="suicides_no",
    title="Suicide number by sex in Croatia",
    figsize=(15,5), stacked=True,colormap = "plasma")
In [80]:
suicide_bar = suicide_2016_Cyprus.plot.bar(
    x="age", y="suicides_no",
    title="Suicide number by age in Cyprus",
    figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Cyprus.plot.bar(
    x="sex", y="suicides_no",
    title="Suicide number by sex in Cyprus",
    figsize=(15,5), stacked=True,colormap = "plasma")
In [81]:
suicide_bar = suicide_2016_Czech.plot.bar(
    x="age", y="suicides_no",
    title="Suicide number by age in Czech Republic",
    figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Czech.plot.bar(
    x="sex", y="suicides_no",
    title="Suicide number by sex in Czech Republic",
    figsize=(15,5), stacked=True,colormap = "plasma")
In [82]:
suicide_bar = suicide_2016_Grenada.plot.bar(
    x="age", y="suicides_no",
    title="Suicide number by age in Grenada",
    figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Grenada.plot.bar(
    x="sex", y="suicides_no",
    title="Suicide number by sex in Grenada",
    figsize=(15,5), stacked=True,colormap = "plasma")
In [83]:
suicide_bar = suicide_2016_Hungary.plot.bar(
    x="age", y="suicides_no",
    title="Suicide number by age in Hungary",
    figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Hungary.plot.bar(
    x="sex", y="suicides_no",
    title="Suicide number by sex in Hungary",
    figsize=(15,5), stacked=True,colormap = "plasma")
In [84]:
suicide_bar = suicide_2016_Lithuania.plot.bar(
    x="age", y="suicides_no",
    title="Suicide number by age in Lithuania",
    figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Lithuania.plot.bar(
    x="sex", y="suicides_no",
    title="Suicide number by sex in Lithuania",
    figsize=(15,5), stacked=True,colormap = "plasma")
In [85]:
suicide_bar = suicide_2016_Mauritius.plot.bar(
    x="age", y="suicides_no",
    title="Suicide number by age in Mauritius",
    figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Mauritius.plot.bar(
    x="sex", y="suicides_no",
    title="Suicide number by sex in Mauritius",
    figsize=(15,5), stacked=True,colormap = "plasma")
In [86]:
suicide_bar = suicide_2016_Mongolia.plot.bar(
    x="age", y="suicides_no",
    title="Suicide number by age in Mongolia",
    figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Mongolia.plot.bar(
    x="sex", y="suicides_no",
    title="Suicide number by sex in Mongolia",
    figsize=(15,5), stacked=True,colormap = "plasma")
In [87]:
suicide_bar = suicide_2016_Netherlands.plot.bar(
    x="age", y="suicides_no",
    title="Suicide number by age in Netherlands",
    figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Netherlands.plot.bar(
    x="sex", y="suicides_no",
    title="Suicide number by sex in Netherlands",
    figsize=(15,5), stacked=True,colormap = "plasma")
In [88]:
suicide_bar = suicide_2016_Qatar.plot.bar(
    x="age", y="suicides_no",
    title="Suicide number by age in Qatar",
    figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Qatar.plot.bar(
    x="sex", y="suicides_no",
    title="Suicide number by sex in Qatar",
    figsize=(15,5), stacked=True,colormap = "plasma")
In [89]:
suicide_bar = suicide_2016_Romania.plot.bar(
    x="age", y="suicides_no",
    title="Suicide number by age in Romania",
    figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Romania.plot.bar(
    x="sex", y="suicides_no",
    title="Suicide number by sex in Romania",
    figsize=(15,5), stacked=True,colormap = "plasma")
In [90]:
suicide_bar = suicide_2016_Sweden.plot.bar(
    x="age", y="suicides_no",
    title="Suicide number by age in Sweden",
    figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Sweden.plot.bar(
    x="sex", y="suicides_no",
    title="Suicide number by sex in Sweden",
    figsize=(15,5), stacked=True,colormap = "plasma")
In [91]:
suicide_bar = suicide_2016_Thailand.plot.bar(
    x="age", y="suicides_no",
    title="Suicide number by age in Thailand",
    figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Thailand.plot.bar(
    x="sex", y="suicides_no",
    title="Suicide number by sex in Thailand",
    figsize=(15,5), stacked=True,colormap = "plasma")
In [92]:
suicide_bar = suicide_2016_Iceland.plot.bar(
    x="age", y="suicides_no",
    title="Suicide number by age in Iceland",
    figsize=(15,5), stacked=True,colormap = "viridis")
suicide_bar_1 = suicide_2016_Iceland.plot.bar(
    x="sex", y="suicides_no",
    title="Suicide number by sex in Iceland",
    figsize=(15,5), stacked=True,colormap = "plasma")
In [93]:
arm = suicide_2016.loc[suicide['country'] == 'Armenia', 'suicides_no'].sum()
print ("%d people commited suicide in Armenia, 2016" %arm)

aus = suicide_2016.loc[suicide['country'] == 'Austria', 'suicides_no'].sum()
print ("%d people commited suicide in Austria, 2016" %aus)

cro = suicide_2016.loc[suicide['country'] == 'Croatia', 'suicides_no'].sum()
print ("%d people commited suicide in Croatia, 2016" %cro)

cyp = suicide_2016.loc[suicide['country'] == 'Cyprus', 'suicides_no'].sum()
print ("%d people commited suicide in Cyprus, 2016" %cyp)

cze = suicide_2016.loc[suicide['country'] == 'Czech Republic', 'suicides_no'].sum()
print ("%d people commited suicide in Czech Republic, 2016" %cze)

gre = suicide_2016.loc[suicide['country'] == 'Grenada', 'suicides_no'].sum()
print ("%d people commited suicide in Grenada, 2016" %gre)

hun = suicide_2016.loc[suicide['country'] == 'Hungary', 'suicides_no'].sum()
print ("%d people commited suicide in Hungary, 2016" %hun)

ice = suicide_2016.loc[suicide['country'] == 'Iceland', 'suicides_no'].sum()
print ("%d people commited suicide in Iceland, 2016" %ice)

lit = suicide_2016.loc[suicide['country'] == 'Lithuania', 'suicides_no'].sum()
print ("%d people commited suicide in Lithuania in 2016" %lit)

mau = suicide_2016.loc[suicide['country'] == 'Mauritius', 'suicides_no'].sum()
print ("%d people commited suicide in Mauritius in 2016" %mau)

mon = suicide_2016.loc[suicide['country'] == 'Mongolia', 'suicides_no'].sum()
print ("%d people commited suicide in Mongolia, 2016" %mon)

net = suicide_2016.loc[suicide['country'] == 'Netherlands', 'suicides_no'].sum()
print ("%d people commited suicide in Netherlands, 2016" %net)

qat = suicide_2016.loc[suicide['country'] == 'Qatar', 'suicides_no'].sum()
print ("%d people commited suicide in Qatar, 2016" %qat)

rom = suicide_2016.loc[suicide['country'] == 'Romania', 'suicides_no'].sum()
print ("%d people commited suicide in Romania, 2016" %rom)

swe = suicide_2016.loc[suicide['country'] == 'Sweden', 'suicides_no'].sum()
print ("%d people commited suicide in Sweden, 2016" %swe)

thai = suicide_2016.loc[suicide['country'] == 'Thailand', 'suicides_no'].sum()
print ("%d people commited suicide in Thailand, 2016" %thai)
67 people commited suicide in Armenia, 2016
1201 people commited suicide in Austria, 2016
683 people commited suicide in Croatia, 2016
36 people commited suicide in Cyprus, 2016
1318 people commited suicide in Czech Republic, 2016
0 people commited suicide in Grenada, 2016
1761 people commited suicide in Hungary, 2016
40 people commited suicide in Iceland, 2016
822 people commited suicide in Lithuania in 2016
98 people commited suicide in Mauritius in 2016
423 people commited suicide in Mongolia, 2016
1886 people commited suicide in Netherlands, 2016
68 people commited suicide in Qatar, 2016
1953 people commited suicide in Romania, 2016
1130 people commited suicide in Sweden, 2016
4117 people commited suicide in Thailand, 2016
In [94]:
totoal_bycountry =[['Armenia', arm], ['Austria', aus], ['Croatia', cro], 
                  ['Cyprus', cyp], ['Czech Republic', cze], ['Grenada', gre],
                  ['Hungary', hun], ['Iceland', ice], ['Lithuania', lit], 
                  ['Mauritius', mau], ['Mongolia', mon], ['Netherlands', net],
                  ['Qatar', qat], ['Romania', rom], ['Sweden', swe], 
                    ['Thailand', thai]]
tot_country = pd.DataFrame(totoal_bycountry,columns = ['Country', 'Total N'])

tot_country.sort_values(by='Total N', ascending=False)
Out[94]:
Country Total N
15 Thailand 4117
13 Romania 1953
11 Netherlands 1886
6 Hungary 1761
4 Czech Republic 1318
1 Austria 1201
14 Sweden 1130
8 Lithuania 822
2 Croatia 683
10 Mongolia 423
9 Mauritius 98
12 Qatar 68
0 Armenia 67
7 Iceland 40
3 Cyprus 36
5 Grenada 0
In [95]:
suicide_bar = tot_country.plot.bar(
    x="Country", y="Total N",
    title="Total number committed suicides by country",
    figsize=(15,5), stacked=True,colormap = "summer")
In [96]:
# Deaths dataset
death
Out[96]:
Entity Year Meningitis (deaths) Lower respiratory infections (deaths) Intestinal infectious diseases (deaths) Protein-energy malnutrition (deaths) Terrorism (deaths) Cardiovascular diseases (deaths) Dementia (deaths) Kidney disease (deaths) ... Neonatal disorders (deaths) Alcohol use disorders (deaths) Natural disasters (deaths) Diarrheal diseases (deaths) Heat (hot and cold exposure) (deaths) Nutritional deficiencies (deaths) Suicide (deaths) Conflict (deaths) Diabetes (deaths) Poisonings (deaths)
1 Afghanistan 2000 9761.290717 31769.17538 358.006996 2114.510638 38.0 54523.55244 2236.612061 3468.222320 ... 29562.611950 91.598058 0.000000 12938.353280 134.081689 2202.312536 1171.900184 5429.002257 4012.101851 257.354125
2 Afghanistan 2001 9477.582051 30505.52451 359.769786 1966.565922 174.0 54850.34660 2267.435697 3468.138292 ... 29730.894280 90.293732 4.000000 12136.210730 463.657061 2052.330272 1191.548668 5727.006858 4147.689517 254.529894
3 Afghanistan 2002 8335.205303 28909.06415 364.035375 1857.651707 74.0 54810.28059 2295.084048 3470.397898 ... 28324.189760 90.896730 1285.999798 11363.246050 140.765586 1943.242372 1238.790835 985.000023 4257.009130 257.019972
4 Afghanistan 2003 9912.024674 33217.86158 449.369180 2110.147100 163.0 54822.62001 2323.883437 3649.958559 ... 31901.533800 92.396359 137.000000 13399.174680 157.926775 2211.928636 1297.286529 864.000077 4398.482507 294.030425
5 Afghanistan 2004 10282.723100 33809.98317 486.395564 2186.575976 275.0 54638.28649 2356.687144 3731.666841 ... 30717.445770 92.977619 18.000000 13574.916390 163.304128 2293.347842 1321.098290 1042.999637 4508.122915 307.235313
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
4286 Zimbabwe 2013 1820.090331 13108.15135 25.015658 3507.171892 1.0 16900.85809 1190.558139 1672.878615 ... 9439.290155 73.649954 125.000002 5129.483596 44.403541 3557.450127 2561.496069 7.000000 2599.112561 410.802638
4287 Zimbabwe 2014 1769.993458 12841.51067 25.623337 3380.319464 0.0 16755.84307 1191.914868 1677.650653 ... 9106.657298 73.460128 8.500000 4946.075661 43.073231 3428.811706 2554.170577 3.000000 2625.681137 406.351616
4288 Zimbabwe 2015 1728.691503 12637.72861 25.415872 3263.941226 NaN 16691.10908 1201.436860 1696.631617 ... 8887.033499 74.605887 15.500000 4737.642966 42.139866 3310.899062 2583.031015 12.000000 2657.480378 404.641729
4289 Zimbabwe 2016 1703.437894 12495.14729 25.752116 3188.723249 NaN 16781.94657 1223.666312 1728.189418 ... 8653.776455 75.907792 31.000000 4602.100769 41.675497 3235.070735 2619.243794 6.000000 2712.995017 405.940831
4290 Zimbabwe 2017 1677.007331 12369.65470 NaN 3111.873502 0.0 16976.90237 1246.101126 1739.892243 ... 8411.915534 77.192339 0.000000 4602.593760 41.433611 3157.591804 2647.468528 5.000000 2746.739645 405.377266

4290 rows × 35 columns

In [97]:
death_2017 = death[death.Year == 2017]
death_2017
Out[97]:
Entity Year Meningitis (deaths) Lower respiratory infections (deaths) Intestinal infectious diseases (deaths) Protein-energy malnutrition (deaths) Terrorism (deaths) Cardiovascular diseases (deaths) Dementia (deaths) Kidney disease (deaths) ... Neonatal disorders (deaths) Alcohol use disorders (deaths) Natural disasters (deaths) Diarrheal diseases (deaths) Heat (hot and cold exposure) (deaths) Nutritional deficiencies (deaths) Suicide (deaths) Conflict (deaths) Diabetes (deaths) Poisonings (deaths)
18 Afghanistan 2017 6588.668300 2.143116e+04 NaN 1369.742538 6092.0 5.611858e+04 2.893171e+03 3.895213e+03 ... 2.752174e+04 125.474868 155.000000 6.176201e+03 153.383019 1440.662274 1725.624776 1662.000127 5.978462e+03 365.394197
36 Albania 2017 18.606850 3.816531e+02 NaN 3.257634 0.0 1.214497e+04 1.337440e+03 3.625372e+02 ... 1.836851e+02 15.465368 1.000000 6.939839e+00 10.528083 4.458938 161.977426 0.000000 1.350015e+02 11.384000
54 Algeria 2017 379.614524 4.723762e+03 NaN 80.517066 12.0 7.938907e+04 8.175242e+03 4.577023e+03 ... 6.511280e+03 130.332484 0.000000 3.772447e+02 50.093911 97.704089 1698.665146 134.999996 5.201535e+03 366.645603
72 American Samoa 2017 0.731541 1.379903e+01 NaN 1.468605 NaN 9.984946e+01 8.453716e+00 2.352140e+01 ... 4.608330e+00 0.344536 0.000000 1.180293e+00 1.142969 1.572362 3.481451 0.000000 3.324538e+01 0.407851
90 Andean Latin America 2017 581.273232 2.714703e+04 NaN 1759.381212 NaN 6.267408e+04 1.781604e+04 1.419107e+04 ... 8.474229e+03 1015.506167 100.000000 2.145729e+03 274.305127 1994.021903 3263.203985 0.000000 1.159087e+04 419.109363
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
4205 Western Sub-Saharan Africa 2017 97280.910310 3.555672e+05 NaN 56167.920230 NaN 3.432830e+05 4.119791e+04 3.971805e+04 ... 3.520668e+05 4288.644450 399.003931 2.771202e+05 3609.520296 58239.213610 22262.875450 6222.060835 4.068288e+04 4219.994234
4223 World 2017 288021.105400 2.558606e+06 NaN 231770.992000 26445.0 1.779095e+07 2.514619e+06 1.230168e+06 ... 1.783770e+06 184934.241800 9602.935057 1.569556e+06 53349.518780 269996.917700 793823.469100 129720.145700 1.369849e+06 72370.531920
4251 Yemen 2017 670.912350 6.365553e+03 NaN 652.747746 762.0 5.336712e+04 2.671958e+03 1.964220e+03 ... 1.804043e+04 76.494244 50.000000 8.124504e+03 61.428043 745.360757 1469.601158 16810.957360 2.100061e+03 440.942178
4272 Zambia 2017 2459.456832 8.979435e+03 NaN 2586.370661 0.0 1.215708e+04 1.375849e+03 1.852649e+03 ... 9.688018e+03 202.315127 0.000000 7.748348e+03 19.930019 2637.116209 1160.836050 1.000000 2.351565e+03 180.807934
4290 Zimbabwe 2017 1677.007331 1.236965e+04 NaN 3111.873502 0.0 1.697690e+04 1.246101e+03 1.739892e+03 ... 8.411916e+03 77.192339 0.000000 4.602594e+03 41.433611 3157.591804 2647.468528 5.000000 2.746740e+03 405.377266

236 rows × 35 columns

In [98]:
# to get rid of NaNs. I will replace it with space/blank, because there are 0 (zeros) for some columns
import numpy as np 
death_2017_clean = death_2017.replace(np.nan, ' ', regex=True)
death_2017_clean
Out[98]:
Entity Year Meningitis (deaths) Lower respiratory infections (deaths) Intestinal infectious diseases (deaths) Protein-energy malnutrition (deaths) Terrorism (deaths) Cardiovascular diseases (deaths) Dementia (deaths) Kidney disease (deaths) ... Neonatal disorders (deaths) Alcohol use disorders (deaths) Natural disasters (deaths) Diarrheal diseases (deaths) Heat (hot and cold exposure) (deaths) Nutritional deficiencies (deaths) Suicide (deaths) Conflict (deaths) Diabetes (deaths) Poisonings (deaths)
18 Afghanistan 2017 6588.67 21431.2 1369.74 6092 56118.6 2893.17 3895.21 ... 27521.7 125.475 155 6176.2 153.383 1440.66 1725.62 1662 5978.46 365.394
36 Albania 2017 18.6069 381.653 3.25763 0 12145 1337.44 362.537 ... 183.685 15.4654 1 6.93984 10.5281 4.45894 161.977 0 135.002 11.384
54 Algeria 2017 379.615 4723.76 80.5171 12 79389.1 8175.24 4577.02 ... 6511.28 130.332 0 377.245 50.0939 97.7041 1698.67 135 5201.54 366.646
72 American Samoa 2017 0.731541 13.799 1.46861 99.8495 8.45372 23.5214 ... 4.60833 0.344536 0 1.18029 1.14297 1.57236 3.48145 0 33.2454 0.407851
90 Andean Latin America 2017 581.273 27147 1759.38 62674.1 17816 14191.1 ... 8474.23 1015.51 100 2145.73 274.305 1994.02 3263.2 0 11590.9 419.109
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
4205 Western Sub-Saharan Africa 2017 97280.9 355567 56167.9 343283 41197.9 39718 ... 352067 4288.64 399.004 277120 3609.52 58239.2 22262.9 6222.06 40682.9 4219.99
4223 World 2017 288021 2.55861e+06 231771 26445 1.77909e+07 2.51462e+06 1.23017e+06 ... 1.78377e+06 184934 9602.94 1.56956e+06 53349.5 269997 793823 129720 1.36985e+06 72370.5
4251 Yemen 2017 670.912 6365.55 652.748 762 53367.1 2671.96 1964.22 ... 18040.4 76.4942 50 8124.5 61.428 745.361 1469.6 16811 2100.06 440.942
4272 Zambia 2017 2459.46 8979.44 2586.37 0 12157.1 1375.85 1852.65 ... 9688.02 202.315 0 7748.35 19.93 2637.12 1160.84 1 2351.57 180.808
4290 Zimbabwe 2017 1677.01 12369.7 3111.87 0 16976.9 1246.1 1739.89 ... 8411.92 77.1923 0 4602.59 41.4336 3157.59 2647.47 5 2746.74 405.377

236 rows × 35 columns

In [99]:
del death_2017_clean['Year']
death_2017_clean
Out[99]:
Entity Meningitis (deaths) Lower respiratory infections (deaths) Intestinal infectious diseases (deaths) Protein-energy malnutrition (deaths) Terrorism (deaths) Cardiovascular diseases (deaths) Dementia (deaths) Kidney disease (deaths) Respiratory diseases (deaths) ... Neonatal disorders (deaths) Alcohol use disorders (deaths) Natural disasters (deaths) Diarrheal diseases (deaths) Heat (hot and cold exposure) (deaths) Nutritional deficiencies (deaths) Suicide (deaths) Conflict (deaths) Diabetes (deaths) Poisonings (deaths)
18 Afghanistan 6588.67 21431.2 1369.74 6092 56118.6 2893.17 3895.21 6917.37 ... 27521.7 125.475 155 6176.2 153.383 1440.66 1725.62 1662 5978.46 365.394
36 Albania 18.6069 381.653 3.25763 0 12145 1337.44 362.537 736.029 ... 183.685 15.4654 1 6.93984 10.5281 4.45894 161.977 0 135.002 11.384
54 Algeria 379.615 4723.76 80.5171 12 79389.1 8175.24 4577.02 5508.42 ... 6511.28 130.332 0 377.245 50.0939 97.7041 1698.67 135 5201.54 366.646
72 American Samoa 0.731541 13.799 1.46861 99.8495 8.45372 23.5214 16.8752 ... 4.60833 0.344536 0 1.18029 1.14297 1.57236 3.48145 0 33.2454 0.407851
90 Andean Latin America 581.273 27147 1759.38 62674.1 17816 14191.1 14001 ... 8474.23 1015.51 100 2145.73 274.305 1994.02 3263.2 0 11590.9 419.109
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
4205 Western Sub-Saharan Africa 97280.9 355567 56167.9 343283 41197.9 39718 57615.2 ... 352067 4288.64 399.004 277120 3609.52 58239.2 22262.9 6222.06 40682.9 4219.99
4223 World 288021 2.55861e+06 231771 26445 1.77909e+07 2.51462e+06 1.23017e+06 3.9142e+06 ... 1.78377e+06 184934 9602.94 1.56956e+06 53349.5 269997 793823 129720 1.36985e+06 72370.5
4251 Yemen 670.912 6365.55 652.748 762 53367.1 2671.96 1964.22 4967.91 ... 18040.4 76.4942 50 8124.5 61.428 745.361 1469.6 16811 2100.06 440.942
4272 Zambia 2459.46 8979.44 2586.37 0 12157.1 1375.85 1852.65 2227.18 ... 9688.02 202.315 0 7748.35 19.93 2637.12 1160.84 1 2351.57 180.808
4290 Zimbabwe 1677.01 12369.7 3111.87 0 16976.9 1246.1 1739.89 3411.96 ... 8411.92 77.1923 0 4602.59 41.4336 3157.59 2647.47 5 2746.74 405.377

236 rows × 34 columns

In [100]:
# World 2017
import plotly.graph_objects as go

fig = go.Figure(go.Bar(
            x=death_2017_clean.iloc[232],
            y=[' ', 'Meningitis (deaths)', 'Lower respiratory infections (deaths)', 'Intestinal infectious diseases (deaths)', 
               'Protein-energy malnutrition (deaths)', 'Terrorism (deaths)', 'Cardiovascular diseases (deaths)', 
               'Dementia (deaths)', 'Kidney disease (deaths)','Respiratory diseases (deaths)', 
               'Liver diseases (deaths)', 'Digestive diseases (deaths)','Hepatitis (deaths)', 'Cancers (deaths)', 
               'Parkinson disease (deaths)','Fire (deaths)', 'Malaria (deaths)', 'Drowning (deaths)' 
               ],
            orientation='h'))
fig.update_layout(title= 'Death causes in the World, 2017')
fig.show()


import plotly.graph_objects as go

fig_2 = go.Figure(go.Bar(
            x=death_2017_clean.iloc[232],
            y=[' ', 'Homicide (deaths)', 'HIV/AIDS (deaths)', 'Drug use disorders (deaths)', 'Tuberculosis (deaths)', 
               'Road injuries (deaths)', 'Maternal disorders (deaths)', 'Neonatal disorders (deaths)', 
               'Alcohol use disorders (deaths)', 'Natural disasters (deaths)','Diarrheal diseases (deaths)', 
               'Heat (hot and cold exposure) (deaths)', 'Nutritional deficiencies (deaths)','Suicide (deaths)', 
               'Conflict (deaths)', 'Diabetes (deaths)', 'Poisonings (deaths)' 
               ],
            orientation='h'))
fig_2.update_layout(title= 'Death causes in the World, 2017')
fig_2.show()
In [101]:
death_16 = death[death.Year == 2016]

# to get rid of NaNs. I will replace it with space/blank, because there are 0 (zeros) for some columns
import numpy as np 
death_2016 = death_16.replace(np.nan, ' ', regex=True)

# removing Year column
del death_2016['Year']
death_2016
Out[101]:
Entity Meningitis (deaths) Lower respiratory infections (deaths) Intestinal infectious diseases (deaths) Protein-energy malnutrition (deaths) Terrorism (deaths) Cardiovascular diseases (deaths) Dementia (deaths) Kidney disease (deaths) Respiratory diseases (deaths) ... Neonatal disorders (deaths) Alcohol use disorders (deaths) Natural disasters (deaths) Diarrheal diseases (deaths) Heat (hot and cold exposure) (deaths) Nutritional deficiencies (deaths) Suicide (deaths) Conflict (deaths) Diabetes (deaths) Poisonings (deaths)
17 Afghanistan 6672.9 21359.3 435.835 1363.98 6142 54963.5 2838.01 3831 6797.1 ... 26997.5 121.277 78 6058.45 150.88 1434.74 1674.42 28050.9 5824.42 354.723
35 Albania 18.7919 372.205 0.167811 3.29471 0 11846.1 1289.41 356.822 715.909 ... 190.96 15.3822 2 6.84983 4.56848 4.48872 163.42 0 131.822 11.4658
53 Algeria 393.549 4757.14 153.757 84.1844 9 77330.6 7841.3 4487.79 5375.6 ... 7077.24 127.157 0 387.422 50.3819 101.516 1702.53 92 5057.47 373.85
71 American Samoa 0.737231 13.5835 0.784349 1.46088 97.9794 8.2553 23.2085 16.5002 ... 4.6685 0.341592 0 1.15789 1.13517 1.56459 3.45456 0 32.3527 0.404789
89 Andean Latin America 594.212 26697.8 11.5673 1730.82 60523.5 16980.9 13851.4 13663.2 ... 8878.53 970.112 687 2106.83 273.894 1964.44 3215.56 23 11292.2 418.936
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
4222 World 295879 2.57463e+06 155449 236430 34871 1.75244e+07 2.44004e+06 1.21696e+06 3.82662e+06 ... 1.85292e+06 181679 7261.25 1.55085e+06 54183.1 274881 788675 158356 1.34643e+06 73643.1
4233 World (excluding China) ...
4250 Yemen 673.596 6439.6 319.523 673.793 1517 51235 2556.93 1897.18 4763.32 ... 18323.5 73.3884 40 7138.14 60.277 766.917 1416.1 15210 2007.85 434.682
4271 Zambia 2481.53 9037.07 419.401 2653.46 11754 1316.34 1800.57 2165.87 ... 9617.3 192.483 0 7640.29 19.8943 2704.47 1116.18 3 2262.24 179.407
4289 Zimbabwe 1703.44 12495.1 25.7521 3188.72 16781.9 1223.67 1728.19 3378.51 ... 8653.78 75.9078 31 4602.1 41.6755 3235.07 2619.24 6 2713 405.941

237 rows × 34 columns

In [102]:
#World 2016
import plotly.graph_objects as go

fig = go.Figure(go.Bar(
            x=death_2016.iloc[232],
            y=[' ', 'Meningitis (deaths)', 'Lower respiratory infections (deaths)', 'Intestinal infectious diseases (deaths)', 
               'Protein-energy malnutrition (deaths)', 'Terrorism (deaths)', 'Cardiovascular diseases (deaths)', 
               'Dementia (deaths)', 'Kidney disease (deaths)','Respiratory diseases (deaths)', 
               'Liver diseases (deaths)', 'Digestive diseases (deaths)','Hepatitis (deaths)', 'Cancers (deaths)', 
               'Parkinson disease (deaths)','Fire (deaths)', 'Malaria (deaths)', 'Drowning (deaths)' 
               ],
            orientation='h'))
fig.update_layout(title= 'Death causes in the World, 2016')
fig.show()


import plotly.graph_objects as go

fig = go.Figure(go.Bar(
            x=death_2016.iloc[232],
            y=[' ', 'Homicide (deaths)', 'HIV/AIDS (deaths)', 'Drug use disorders (deaths)', 'Tuberculosis (deaths)', 
               'Road injuries (deaths)', 'Maternal disorders (deaths)', 'Neonatal disorders (deaths)', 
               'Alcohol use disorders (deaths)', 'Natural disasters (deaths)','Diarrheal diseases (deaths)', 
               'Heat (hot and cold exposure) (deaths)', 'Nutritional deficiencies (deaths)','Suicide (deaths)', 
               'Conflict (deaths)', 'Diabetes (deaths)', 'Poisonings (deaths)' 
               ],
            orientation='h'))
fig.update_layout(title= 'Death causes in the World, 2016')
fig.show()
In [103]:
death_00 = death[death.Year == 2000]

# to get rid of NaNs. I will replace it with space/blank, because there are 0 (zeros) for some columns
import numpy as np 
death_2000 = death_00.replace(np.nan, ' ', regex=True)

# removing Year column
del death_2000['Year']
death_2000
Out[103]:
Entity Meningitis (deaths) Lower respiratory infections (deaths) Intestinal infectious diseases (deaths) Protein-energy malnutrition (deaths) Terrorism (deaths) Cardiovascular diseases (deaths) Dementia (deaths) Kidney disease (deaths) Respiratory diseases (deaths) ... Neonatal disorders (deaths) Alcohol use disorders (deaths) Natural disasters (deaths) Diarrheal diseases (deaths) Heat (hot and cold exposure) (deaths) Nutritional deficiencies (deaths) Suicide (deaths) Conflict (deaths) Diabetes (deaths) Poisonings (deaths)
1 Afghanistan 9761.29 31769.2 358.007 2114.51 38 54523.6 2236.61 3468.22 7023.03 ... 29562.6 91.5981 0 12938.4 134.082 2202.31 1171.9 5429 4012.1 257.354
19 Albania 54.1657 855.86 0.171205 24.6265 0 8103.51 748.015 277.134 722.434 ... 610.579 10.4028 0 16.3217 6.08059 26.0305 150.23 1 117.687 21.1046
37 Algeria 583.78 4891.74 244.695 265.3 528 55688.3 4396.88 2437.07 4057.16 ... 11087.5 97.8505 48 1282.97 54.4892 294.331 1558.66 2534 2444.07 399.594
55 American Samoa 0.957988 13.319 0.909666 1.87484 79.9664 6.12715 12.8173 15.9694 ... 10.4212 0.3319 0 1.06018 1.14048 1.95258 3.33476 0 25.1662 0.420565
73 Andean Latin America 1143.35 26431.5 13.4321 4361.24 44682 7876.26 8008.16 7669.58 ... 16265.1 1379.06 117 5142.32 327 4726.9 2497.67 9 5760.4 545.515
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
4206 World 422671 2.97669e+06 199954 485909 4403 1.36987e+07 1.38256e+06 777533 3.58898e+06 ... 2.65827e+06 169033 8051.61 2.13216e+06 67334.1 534575 832891 122799 851460 80053.1
4234 Yemen 1036.42 10724.7 395.787 1628.56 19 36109 1289.65 1338.34 3462.68 ... 25968.6 50.0431 0 18057 55.6461 1769.77 926.274 19 1114.14 422.012
4252 Yugoslavia 5 ...
4255 Zambia 3562.19 12168.8 352.982 4457.26 0 10429 792.231 1459.15 1901.38 ... 9588.11 127.62 0 14040.5 21.1856 4574.25 811.501 1 1669.88 166.426
4273 Zimbabwe 1543.81 10163.9 13.2201 2650.51 0 15971.6 1351.69 1441.31 3240.61 ... 7540.43 74.1717 70 4411.67 41.5102 2704.48 2321.51 29 2108.3 348.881

240 rows × 34 columns

In [104]:
# World 2000 
import plotly.graph_objects as go

fig = go.Figure(go.Bar(
            x=death_2000.iloc[235],
            y=[' ', 'Meningitis (deaths)', 'Lower respiratory infections (deaths)', 'Intestinal infectious diseases (deaths)', 
               'Protein-energy malnutrition (deaths)', 'Terrorism (deaths)', 'Cardiovascular diseases (deaths)', 
               'Dementia (deaths)', 'Kidney disease (deaths)','Respiratory diseases (deaths)', 
               'Liver diseases (deaths)', 'Digestive diseases (deaths)','Hepatitis (deaths)', 'Cancers (deaths)', 
               'Parkinson disease (deaths)','Fire (deaths)', 'Malaria (deaths)', 'Drowning (deaths)', 
               ],
            orientation='h'))
fig.update_layout(title= 'Death causes in the World, 2000')
fig.show()


import plotly.graph_objects as go

fig = go.Figure(go.Bar(
            x=death_2000.iloc[235],
            y=[' ', 'Homicide (deaths)', 'HIV/AIDS (deaths)', 'Drug use disorders (deaths)', 'Tuberculosis (deaths)', 
               'Road injuries (deaths)', 'Maternal disorders (deaths)', 'Neonatal disorders (deaths)', 
               'Alcohol use disorders (deaths)', 'Natural disasters (deaths)','Diarrheal diseases (deaths)', 
               'Heat (hot and cold exposure) (deaths)', 'Nutritional deficiencies (deaths)','Suicide (deaths)', 
               'Conflict (deaths)', 'Diabetes (deaths)', 'Poisonings (deaths)' 
               ],
            orientation='h'))
fig.update_layout(title= 'Death causes in the World, 2000')
fig.show()
In [105]:
import plotly.graph_objects as go

labels = ['Meningitis (deaths)', 'Lower respiratory infections (deaths)', 'Intestinal infectious diseases (deaths)', 
               'Protein-energy malnutrition (deaths)', 'Terrorism (deaths)', 'Cardiovascular diseases (deaths)', 
               'Dementia (deaths)', 'Kidney disease (deaths)','Respiratory diseases (deaths)', 
               'Liver diseases (deaths)', 'Digestive diseases (deaths)','Hepatitis (deaths)', 'Cancers (deaths)', 
               'Parkinson disease (deaths)','Fire (deaths)', 'Malaria (deaths)', 'Drowning (deaths)', 
          'Homicide (deaths)', 'HIV/AIDS (deaths)', 'Drug use disorders (deaths)', 'Tuberculosis (deaths)', 
               'Road injuries (deaths)', 'Maternal disorders (deaths)', 'Neonatal disorders (deaths)', 
               'Alcohol use disorders (deaths)', 'Natural disasters (deaths)','Diarrheal diseases (deaths)', 
               'Heat (hot and cold exposure) (deaths)', 'Nutritional deficiencies (deaths)','Suicide (deaths)', 
               'Conflict (deaths)', 'Diabetes (deaths)', 'Poisonings (deaths)'
         ]
values = death_2017_clean.iloc[222]

fig = go.Figure(data=[go.Pie(labels=labels, values=values)])
fig.update_layout(title_text="Death causes in the United States, 2017")
fig.show()
In [106]:
import plotly.graph_objects as go

labels = ['Meningitis (deaths)', 'Lower respiratory infections (deaths)', 'Intestinal infectious diseases (deaths)', 
               'Protein-energy malnutrition (deaths)', 'Terrorism (deaths)', 'Cardiovascular diseases (deaths)', 
               'Dementia (deaths)', 'Kidney disease (deaths)','Respiratory diseases (deaths)', 
               'Liver diseases (deaths)', 'Digestive diseases (deaths)','Hepatitis (deaths)', 'Cancers (deaths)', 
               'Parkinson disease (deaths)','Fire (deaths)', 'Malaria (deaths)', 'Drowning (deaths)', 
          'Homicide (deaths)', 'HIV/AIDS (deaths)', 'Drug use disorders (deaths)', 'Tuberculosis (deaths)', 
               'Road injuries (deaths)', 'Maternal disorders (deaths)', 'Neonatal disorders (deaths)', 
               'Alcohol use disorders (deaths)', 'Natural disasters (deaths)','Diarrheal diseases (deaths)', 
               'Heat (hot and cold exposure) (deaths)', 'Nutritional deficiencies (deaths)','Suicide (deaths)', 
               'Conflict (deaths)', 'Diabetes (deaths)', 'Poisonings (deaths)'
         ]
values = death_2016.iloc[232]

fig = go.Figure(data=[go.Pie(labels=labels, values=values)])
fig.update_layout(title_text="Death causes in the United States, 2016")
fig.show()
In [107]:
import plotly.graph_objects as go

labels = ['Meningitis (deaths)', 'Lower respiratory infections (deaths)', 'Intestinal infectious diseases (deaths)', 
               'Protein-energy malnutrition (deaths)', 'Terrorism (deaths)', 'Cardiovascular diseases (deaths)', 
               'Dementia (deaths)', 'Kidney disease (deaths)','Respiratory diseases (deaths)', 
               'Liver diseases (deaths)', 'Digestive diseases (deaths)','Hepatitis (deaths)', 'Cancers (deaths)', 
               'Parkinson disease (deaths)','Fire (deaths)', 'Malaria (deaths)', 'Drowning (deaths)', 
          'Homicide (deaths)', 'HIV/AIDS (deaths)', 'Drug use disorders (deaths)', 'Tuberculosis (deaths)', 
               'Road injuries (deaths)', 'Maternal disorders (deaths)', 'Neonatal disorders (deaths)', 
               'Alcohol use disorders (deaths)', 'Natural disasters (deaths)','Diarrheal diseases (deaths)', 
               'Heat (hot and cold exposure) (deaths)', 'Nutritional deficiencies (deaths)','Suicide (deaths)', 
               'Conflict (deaths)', 'Diabetes (deaths)', 'Poisonings (deaths)'
         ]
values = death_2000.iloc[235]

fig = go.Figure(data=[go.Pie(labels=labels, values=values)])
fig.update_layout(title_text="Death causes in the United States, 2000")
fig.show()
In [ ]: